﻿/*********************************************
 FileName:ShowPopWnd.cpp
 ProjectName:MobileManage
 Created: mr.l
 FuncTion 个人信息管理类
 Time: 15/7/4.
 *********************************************/

#include "GNS_PlayerMgr.h"
USING_NS_CC;
#define winsize Director::getInstance()->getVisibleSize()

GNS_PlayerMgr::GNS_PlayerMgr(){
    ChooseDayNum=0;
    ChooseMonNum=0;
    pCurrScene=0;
    RevRepMag=0;
    nAgentLevent=10;
    InfoResult_operType=0;
    _playTop=0;
}
GNS_PlayerMgr::~GNS_PlayerMgr(){
}

GNS_PlayerMgr * GNS_PlayerMgr::m_singleton=nullptr;

GNS_PlayerMgr* GNS_PlayerMgr::getInstance(){
	if (nullptr == m_singleton) {
        m_singleton = new GNS_PlayerMgr();
    }
    return m_singleton;
}

void GNS_PlayerMgr::setRemarkName(CMD_SC_GetRemarkNameResult *pGetRemark)
{
	std::lock_guard<std::recursive_mutex> guard(_remarkName);
	//if (m_RemarkName.find(pGetRemark->_lowlineCode) == m_RemarkName.end())
		m_RemarkName[pGetRemark->_lowlineCode] = pGetRemark->_lowlineRemarkName;
}
void GNS_PlayerMgr::setUserExInfoRes(CMD_SC_GetUserExchangeInfoResult * pUserExInfoRes)
{
    map<int,vector<CMD_SC_GetUserExchangeInfoResult> >::iterator it=m_userExInfoRes.find(pUserExInfoRes->_type);
    if (it!=m_userExInfoRes.end()) {
        it->second.push_back(*pUserExInfoRes);
    }else{
        vector<CMD_SC_GetUserExchangeInfoResult> mUserExInfoRes;
        mUserExInfoRes.push_back(*pUserExInfoRes);
        m_userExInfoRes.insert(pair<int, vector<CMD_SC_GetUserExchangeInfoResult> >(pUserExInfoRes->_type,mUserExInfoRes));
    }
}
void GNS_PlayerMgr::setGameDownUrl(CMD_SC_GetGameDownLoadURLResult *pGameDown)
{
	std::lock_guard<std::recursive_mutex> guard(_GameDown);
    m_GameDown.push_back(*pGameDown);
}

void GNS_PlayerMgr::setUserManage(CMD_SC_GetAgentUserManageLogResult *pUserManage)
{
	std::lock_guard<std::recursive_mutex> guard(_UserManage);
    m_UserManage.push_back(*pUserManage);
}

void GNS_PlayerMgr::setExList(CMD_SC_GetExchangeListResult *pExList)
{
	std::lock_guard<std::recursive_mutex> guard(_ExListRes);
    m_ExListRes.push_back(*pExList);
}

void GNS_PlayerMgr::setUserNotInfo(CMD_SC_GetUserNotExchangeInfoResult *pUserNotInfo)
{
	std::lock_guard<std::recursive_mutex> guard(_UserNotInfo);
    if (find(m_UserNotInfo.begin(),m_UserNotInfo.end(), *pUserNotInfo)== m_UserNotInfo.end())
    {
        m_UserNotInfo.push_back(*pUserNotInfo);
    }
}

void GNS_PlayerMgr::setAgProPer(CMD_SC_GetAgentProfitPercentResult *pAgProPer)
{
	std::lock_guard<std::recursive_mutex> guard(_AgProPer);
    m_AgProPer.push_back(*pAgProPer);
}

void GNS_PlayerMgr::setOperatorAgProPer(CMD_SC_GetAgentProfitPercentResult *pOperatorAgProPer)
{
	std::lock_guard<std::recursive_mutex> guard(_OperatorAgent);
    m_OperatorAgent.push_back(*pOperatorAgProPer);
}

void GNS_PlayerMgr::setLowlineInfo(CMD_SC_GetLowlineUserInfoResult *pLowlineInfo)
{
	std::lock_guard<std::recursive_mutex> guard(_LowlineInfo);
    m_LowlineInfo.push_back(*pLowlineInfo);
}

void GNS_PlayerMgr::setAgRation(CMD_SC_GetAgentRechargeRatioResult *pGetAgRation)
{
	std::lock_guard<std::recursive_mutex> guard(_GetAgRation);	// 加锁
    m_GetAgRation.push_back(*pGetAgRation);
}

void GNS_PlayerMgr::setGameReveRes(CMD_SC_GetManToManGameRevenueResult *pGameReveRes)
{
	std::lock_guard<std::recursive_mutex> guard(_GameReveRes);
    m_GameReveRes.push_back(*pGameReveRes);
}

void GNS_PlayerMgr::setGameProReveRes(CMD_SC_GetManToManGameRevenueResult *pGameProReveRes)
{
	std::lock_guard<std::recursive_mutex> guard(_GameProReveRes);
    m_GameProReveRes.push_back(*pGameProReveRes);
}

void GNS_PlayerMgr::setGamePlayReveRes(CMD_SC_GetManToManGameRevenueResult *pGamePlayReveRes)
{
	std::lock_guard<std::recursive_mutex> guard(_GamePlayReveRes);
    m_GamePlayReveRes.push_back(*pGamePlayReveRes);
}

void GNS_PlayerMgr::setPlayProFit(CMD_SC_GetManToMachPlayProfitResult *pPlayProFit)
{
	std::lock_guard<std::recursive_mutex> guard(_PlayProFit);
    m_PlayProFit.push_back(*pPlayProFit);
}

void GNS_PlayerMgr::setPlayProProFit(CMD_SC_GetManToMachPlayProfitResult *pPlayProProFit)
{
	std::lock_guard<std::recursive_mutex> guard(_PlayProProFit);
    m_PlayProProFit.push_back(*pPlayProProFit);
}

void GNS_PlayerMgr::setPlayProPlayFit(CMD_SC_GetManToMachPlayProfitResult *pPlayProPlayFit)
{
	std::lock_guard<std::recursive_mutex> guard(_PlayProPlayFit);
    m_PlayProPlayFit.push_back(*pPlayProPlayFit);
}

void GNS_PlayerMgr::setPlayProRation(CMD_SC_GetManToMachPlayProfitRatioResult *pPlayProRation)
{
	std::lock_guard<std::recursive_mutex> guard(_PlayProRation);
    m_PlayProRation.push_back(*pPlayProRation);
}

void GNS_PlayerMgr::setPlayProProRation(CMD_SC_GetManToMachPlayProfitRatioResult *pPlayProProRation)
{
	std::lock_guard<std::recursive_mutex> guard(_PlayProProRation);
    m_PlayProProRation.push_back(*pPlayProProRation);
}

void GNS_PlayerMgr::setDialyToInfo(CMD_SC_GetDialyExchangeInfoResult *pDialyExInfo)
{
	std::lock_guard<std::recursive_mutex> guard(_DialyToInfo);
    m_DialyToInfo.push_back(*pDialyExInfo);
}

void GNS_PlayerMgr::setDialyTiInfo(CMD_SC_GetDialyExchangeInfoResult *pDialyTiInfo)
{
	std::lock_guard<std::recursive_mutex> guard(_DialyTiInfo);
    m_DialyTiInfo.push_back(*pDialyTiInfo);
}

void GNS_PlayerMgr::setDialyTrInfo(CMD_SC_GetDialyExchangeInfoResult *pDialyTrInfo)
{
	std::lock_guard<std::recursive_mutex> guard(_DialyTrInfo);
    m_DialyTrInfo.push_back(*pDialyTrInfo);
}

void GNS_PlayerMgr::setUserInfoVec(CMD_SC_GetUserExchangeInfoResult *pUserInfo)
{
	std::lock_guard<std::recursive_mutex> guard(_GetUserInfo);
    m_GetUserInfo.push_back(*pUserInfo);
}

void GNS_PlayerMgr::setGameList(CMD_SC_HALLGAME_LIST *pGameList)
{
	std::lock_guard<std::recursive_mutex> guard(_HallGameList);
    m_HallGameList.push_back(*pGameList);
    if (_gameIdName.find(pGameList->nGameId) == _gameIdName.end())
        _gameIdName[pGameList->nGameId] = pGameList->szGameName;
    if (_gameNameId.find(pGameList->szGameName) == _gameNameId.end())
        _gameNameId[pGameList->szGameName] = pGameList->nGameId;
	if (_gameNameType.find(pGameList->szGameName) == _gameNameType.end())
		_gameNameType[pGameList->szGameName] = pGameList->iGameType;
	_gameTypeName[pGameList->iGameType].push_back(pGameList->szGameName);
}

void GNS_PlayerMgr::transferEachTime(int &year,int &month,int &day,const char selDate[])
{
    std::string strTime(selDate);
    year = atoi((strTime.substr(0,4)).c_str());
    month = atoi((strTime.substr(5,2)).c_str());
    day = atoi((strTime.substr(8,2)).c_str());
}

void GNS_PlayerMgr::ClearAllVectorDate()
{
	std::lock_guard<std::recursive_mutex> guard(_clear);
    m_RemarkName.clear();
    m_userExInfoRes.clear();
    m_HallGameList.clear();
    m_UserNotInfo.clear();//获取未读消息
    m_GameDown.clear();
    m_UserManage.clear();
    m_GetAgRation.clear();//获取充值比例
    m_ExListRes.clear();
    m_AgProPer.clear();
    m_OperatorAgent.clear();
    m_LowlineInfo.clear();
    m_GameReveRes.clear();//人机对战收税分成
    m_GameProReveRes.clear();//人机对战收税分成推官员
    m_GamePlayReveRes.clear();//人机对战收税分成玩家
    m_PlayProFit.clear();//人机对战总玩数据
    m_PlayProProFit.clear();//人机对战总玩数据 推广员
    m_PlayProPlayFit.clear();//人机对战总玩数据 玩家
    m_PlayProRation.clear();//人机对战总玩分成
    m_PlayProProRation.clear();//人机对战总玩分成 推广员
    m_DialyToInfo.clear();//充值
    m_DialyTiInfo.clear();//兑奖
    m_DialyTrInfo.clear();//转账
    m_GetUserFailExInfo.clear();
    m_ExListRes1.clear();
    m_GameName.clear();
    m_GetUserInfo.clear();
    _NodeChildVec.clear();
    //_NodeHallVec.clear();
	_mapNodeHall.clear();
}

vector<CMD_SC_GetAgentRechargeRatioResult> *GNS_PlayerMgr::getAgRation()
{
	std::lock_guard<std::recursive_mutex> guard(_GetAgRation);	// 加锁
	return &m_GetAgRation;
}

//获取存储备注名
std::map<int, string> * GNS_PlayerMgr::getRemarkName()
{ 
	std::lock_guard<std::recursive_mutex> guard(_remarkName); 
	return &m_RemarkName; 
}

//存储获取个人充值、兑奖、转账查询
map<int, vector<CMD_SC_GetUserExchangeInfoResult> > * GNS_PlayerMgr::getUserExInfoRes()
{ 
	std::lock_guard<std::recursive_mutex> guard(_userExInfoRes);  
	return &m_userExInfoRes; 
}

//存储获取未读消息
vector<CMD_SC_GetUserNotExchangeInfoResult> * GNS_PlayerMgr::getUserNotInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_UserNotInfo); 
	return &m_UserNotInfo; 
}

//存储获取二维码地址
vector<CMD_SC_GetGameDownLoadURLResult> *GNS_PlayerMgr::getGameDown()
{ 
	std::lock_guard<std::recursive_mutex> guard(_GameDown);  
	return &m_GameDown; 
}

//存储获取管理记录
vector<CMD_SC_GetAgentUserManageLogResult> * GNS_PlayerMgr::getUserManage()
{ 
	std::lock_guard<std::recursive_mutex> guard(_UserManage);  
	return &m_UserManage; 
}

//存储获取运营商/代理商充/兑记录
vector<CMD_SC_GetExchangeListResult> * GNS_PlayerMgr::getExListRes()
{ 
	std::lock_guard<std::recursive_mutex> guard(_ExListRes);  
	return &m_ExListRes; 
}

//存储获取代理商占比
vector<CMD_SC_GetAgentProfitPercentResult> * GNS_PlayerMgr::getAgProPer()
{ 
	std::lock_guard<std::recursive_mutex> guard(_AgProPer);  
	return &m_AgProPer; 
}

//存储获取运营商占比
vector<CMD_SC_GetAgentProfitPercentResult> * GNS_PlayerMgr::getOperatorAgProPer()
{ 
	std::lock_guard<std::recursive_mutex> guard(_OperatorAgent);  
	return &m_OperatorAgent; 
}

void GNS_PlayerMgr::setExList1(CMD_SC_GetAgentProfitPercentResult * pExList1)
{ 
	std::lock_guard<std::recursive_mutex> guard(_ExListRes1); 
	m_ExListRes1.push_back(*pExList1); 
}

vector<CMD_SC_GetAgentProfitPercentResult> * GNS_PlayerMgr::getExListRes1()
{ 
	std::lock_guard<std::recursive_mutex> guard(_ExListRes1); 
	return &m_ExListRes1; 
}

//存储获取直属玩家冲兑
vector<CMD_SC_GetLowlineUserInfoResult> * GNS_PlayerMgr::getLowlineInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_LowlineInfo);  
	return &m_LowlineInfo; 
}

//存储人机对战收税分成
vector<CMD_SC_GetManToManGameRevenueResult> * GNS_PlayerMgr::getGameReveRes()
{ 
	std::lock_guard<std::recursive_mutex> guard(_GameReveRes);  
	return &m_GameReveRes; 
}

//存储人机对战收税分成推广员
vector<CMD_SC_GetManToManGameRevenueResult> * GNS_PlayerMgr::getGameProReveRes()
{ 
	std::lock_guard<std::recursive_mutex> guard(_GameProReveRes);  
	return &m_GameProReveRes; 
}

//存储人机对战收税分成玩家
vector<CMD_SC_GetManToManGameRevenueResult> * GNS_PlayerMgr::getGamePlayReveRes()
{ 
	std::lock_guard<std::recursive_mutex> guard(_GamePlayReveRes);  
	return &m_GamePlayReveRes; 
}

//存储人机对战总玩数据
vector<CMD_SC_GetManToMachPlayProfitResult> * GNS_PlayerMgr::getPlayProFit()
{ 
	std::lock_guard<std::recursive_mutex> guard(_PlayProFit);  
	return &m_PlayProFit; 
}

//存储人机对战总玩数据推广员
vector<CMD_SC_GetManToMachPlayProfitResult> * GNS_PlayerMgr::getPlayProProFit()
{ 
	std::lock_guard<std::recursive_mutex> guard(_PlayProProFit);  
	return &m_PlayProProFit; 
}

//存储人机对战总玩数据玩家
vector<CMD_SC_GetManToMachPlayProfitResult> * GNS_PlayerMgr::getPlayProPlayFit()
{ 
	std::lock_guard<std::recursive_mutex> guard(_PlayProPlayFit);  
	return &m_PlayProPlayFit; 
}

//存储人机对战总玩分成
vector<CMD_SC_GetManToMachPlayProfitRatioResult> * GNS_PlayerMgr::getPlayProRation()
{ 
	std::lock_guard<std::recursive_mutex> guard(_PlayProRation);  
	return &m_PlayProRation; 
}

//存储获取人机对战总玩分成
vector<CMD_SC_GetManToMachPlayProfitRatioResult> * GNS_PlayerMgr::getPlayProProRation()
{ 
	std::lock_guard<std::recursive_mutex> guard(_PlayProProRation);  
	return &m_PlayProProRation; 
}

//存储每日充值数据
vector<CMD_SC_GetDialyExchangeInfoResult> * GNS_PlayerMgr::getDialyToInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_DialyToInfo);  
	return &m_DialyToInfo; 
}

//存储每日兑奖数据
vector<CMD_SC_GetDialyExchangeInfoResult> * GNS_PlayerMgr::getDialyTiInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_DialyTiInfo);  
	return &m_DialyTiInfo; 
}

//存储每日转账数据
vector<CMD_SC_GetDialyExchangeInfoResult> * GNS_PlayerMgr::getDialyTrInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_DialyTrInfo);  
	return &m_DialyTrInfo; 
}

//获取存储游戏列表
vector<CMD_SC_HALLGAME_LIST> * GNS_PlayerMgr::getGameList()
{ 
	std::lock_guard<std::recursive_mutex> guard(_HallGameList);  
	return &m_HallGameList; 
}

//获取存储个人信息
vector<CMD_SC_GetUserExchangeInfoResult> * GNS_PlayerMgr::getUserInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_GetUserInfo);  
	return &m_GetUserInfo; 
}

void GNS_PlayerMgr::setUserExInfo(CMD_SC_GetUserFailExchangeInfoResult * pUserFailExInfo)
{ 
	std::lock_guard<std::recursive_mutex> guard(_GetUserFailExInfo); 
	if (m_GetUserFailExInfo.end() == find(m_GetUserFailExInfo.begin(), m_GetUserFailExInfo.end(),*pUserFailExInfo))
		m_GetUserFailExInfo.push_back(*pUserFailExInfo); 
}

vector<CMD_SC_GetUserFailExchangeInfoResult> * GNS_PlayerMgr::getUserFailExInfo()
{ 
	std::lock_guard<std::recursive_mutex> guard(_GetUserFailExInfo);   
	return &m_GetUserFailExInfo; 
}

map<int, string>& GNS_PlayerMgr::getGameIdInfo()
{ 
	return _gameIdName; 
}
map<string, int>& GNS_PlayerMgr::getGameNameInfo()
{ 
	return _gameNameId; 
}

void GNS_PlayerMgr::setMyUseridx(long long idx)
{ 
	m_MyUserIdx = idx; 
}

long long GNS_PlayerMgr::getMyUseridx()
{ 
	return m_MyUserIdx; 
}

void GNS_PlayerMgr::setMyNickName(char * name)
{
	memcpy(m_MyNickName, name, 33);
}

char * GNS_PlayerMgr::getMyName()
{ 
	return m_MyUserName[0] == 0 ? m_MyUserName : m_MyNickName; 
}

//存储获取当前版本
void GNS_PlayerMgr::setCurrentVersionClient(int Version)
{ 
	VersionClient = Version; 
}

int GNS_PlayerMgr::getCurrentVersionClient()
{ 
	return VersionClient; 
}

//存储获取更新地址
std::string GNS_PlayerMgr::getUpdateURL()
{ 
	return m_UpdateURL; 
}

void GNS_PlayerMgr::setUpdateURL(std::string val)
{ 
	m_UpdateURL = val; 
}

//存储获取服务器版本
void GNS_PlayerMgr::setServerVersion(int version)
{ 
	VersionServer = version; 
}

int GNS_PlayerMgr::getServerVersion()
{ 
	return VersionServer; 
}

//存储获取玩家级别
void GNS_PlayerMgr::setUserLevel(int Level)
{ 
	nAgentLevent = Level; 
}

int GNS_PlayerMgr::getUserLevel()
{ 
	return nAgentLevent; 
}

//存储玩家充值比
void GNS_PlayerMgr::setPlayTop(int Top)
{ 
	_playTop = Top; 
}

int GNS_PlayerMgr::getPlayTop()
{ 
	return _playTop; 
}

void GNS_PlayerMgr::setGameId(const int gameId)
{ 
	_selGameId = gameId; 
}

int &GNS_PlayerMgr::getGameId() 
{ 
	return _selGameId; 
}

map<string, int> &GNS_PlayerMgr::getNameType()
{
	return _gameNameType;
}

map <int, vector<string> > &GNS_PlayerMgr::getGameTypeName()
{
	return _gameTypeName;
}

//获取下级和上级对应映射 key--下级 value--上级
map<int, int>& GNS_PlayerMgr::getUpToLowCode()
{
	return _mapUpToLowCode;
}

void GNS_PlayerMgr::setUpToLowCode(const int lowlineCode, const int uplineCode)
{
	_mapUpToLowCode[lowlineCode] = uplineCode;
}

//获取下级和上级对应映射 key--下级 value--上级
map<int, int>& GNS_PlayerMgr::getCodeAndRatio()
{
	return _mapCodeAndRatio;
}

void GNS_PlayerMgr::setCodeAndRatio(const int lowlineCode, const int rechargeRatio)
{
	_mapCodeAndRatio[lowlineCode] = rechargeRatio;
}

void GNS_PlayerMgr::pushNode(std::string strName, Node* oneNode)
{
	_mapNodeHall[strName] = oneNode;
}

Node* GNS_PlayerMgr::getNode(std::string strName)
{
	return _mapNodeHall[strName];
}

void GNS_PlayerMgr::setVisible()
{
	std::map<std::string, Node*>::iterator mapNameIter = _mapNodeHall.begin();
	for (; mapNameIter != _mapNodeHall.end(); ++mapNameIter)
	{
		if (mapNameIter->second != nullptr)
			mapNameIter->second->setVisible(true);
		else
			mapNameIter->second->setVisible(false);
	}
}

void GNS_PlayerMgr::setVisible(std::string strName, bool bFlag)
{
	if (_mapNodeHall[strName] != nullptr)
		_mapNodeHall[strName]->setVisible(bFlag);
}